#!/bin/bash
# File Name   : sysbench.sh
# Author      : moshan
# Mail        : mo_shan@yeah.net
# Version     : 1.0
# Created Time: 2020-05-07 14:40:43
# Function    : 压测工具
#########################################################################
mysql_conne_route_info=(root 1234567890 192.168.1.10 3306)
threads_num=10
db_name="mstest"
table_num=10
table_size=100000
export PATH="/root/sysbench-master/src:${PATH}"
case ${1} in 
    "--prepare" | "-p")
        sysbench /root/sysbench-master/src/lua/oltp_read_only.lua --mysql-host=${mysql_conne_route_info[2]} \
            --mysql-port=${mysql_conne_route_info[3]} --mysql-db=${db_name} --mysql-user=${mysql_conne_route_info[0]} \
            --mysql-password=${mysql_conne_route_info[1]} --table_size=${table_size} --tables=${table_num} \
            --threads=${threads_num} --events=500000 --report-interval=10 --time=60 prepare
        ;;
    "--cleanup" | "-c")
        sysbench /root/sysbench-master/src/lua/oltp_read_only.lua --mysql-host=${mysql_conne_route_info[2]} \
            --mysql-port=${mysql_conne_route_info[3]} --mysql-db=${db_name} --mysql-user=${mysql_conne_route_info[0]} \
            --mysql-password=${mysql_conne_route_info[1]} --table_size=${table_size} --tables=${table_num} \
            --threads=${threads_num} --events=500000 --report-interval=10 --time=60 cleanup
        ;;
    "--run" | "-r")
        sysbench /root/sysbench-master/src/lua/oltp_update_non_index.lua --mysql-host=${mysql_conne_route_info[2]} \
            --mysql-port=${mysql_conne_route_info[3]} --mysql-db=${db_name} --mysql-user=${mysql_conne_route_info[0]} \
            --mysql-password=${mysql_conne_route_info[1]} --table_size=${table_size} --tables=${table_num} \
            --threads=${threads_num} --events=500000 --report-interval=10 --time=60 run
        ;;
    "--help" | "-h" | *)
        echo -e "\n\t\033[33mUsage: bash ${0} [--prepare|-p|--run|-r|--cleanup|-c|--help|-h]\033[0m\n"
        echo -e "\t\t\033[34m[--prepare|-p] \t\tPrepare test data to MySQL.\033[0m"
        echo -e "\t\t\033[34m[--run|-r]     \t\tStart stress test to MySQL.\033[0m"
        echo -e "\t\t\033[34m[--cleanup|-c] \t\tCleaning up test data from MySQL.\033[0m\n"
        exit 1
        ;;
esac
